﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.IO;

public partial class CMS_ViewListArticle : System.Web.UI.Page
{
    Usas.BLL.Cms.cmsArticle ar = new Usas.BLL.Cms.cmsArticle();
    Usas.BLL.Cms.cmsBorder bo = new Usas.BLL.Cms.cmsBorder();
    Usas.Common.Cms.CurrentInfo cinfo = new Usas.Common.Cms.CurrentInfo();
    Usas.Common.Cms.Role ro = new Usas.Common.Cms.Role();
    Usas.BLL.Cms.AspPager ap = new Usas.BLL.Cms.AspPager();

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            try
            {
                if (Request["page"] == null)
                {
                    ViewBind(1);
                }
                else
                {
                    ViewBind(Convert.ToInt32(Request["page"]));
                }

                MasterPage_MasterPage_CMS mmc = (MasterPage_MasterPage_CMS)this.Page.Master;
                mmc.ManagerHover();

            }
            catch
            { }
        }
    }


    private void ViewBind(int num)
    {

        DataTable dt = null;
        CMS_Control_CacheView ccc = (CMS_Control_CacheView)Page.LoadControl("~/CMS/Control/CacheView.ascx");
        bool edit = false;
        bool view = false;

        if (Request["bid"] != null)
        {
            //目录页
            RouterBar1.IntiBar(CMS_Control_RouterBar.ShowMode.Border, Convert.ToInt32(Request["bid"]), new ArrayList());
            dt = ap.GetBorderTableBySetting(ro.GetSelfSettingRole(), "Del <> 1 and BorderID=" + Request["bid"], 1, -1, "BorderOrder");
            edit = Convert.ToInt32(dt.Rows[0]["edit"]) > 0 ? true : false;
            view = Convert.ToInt32(dt.Rows[0]["view"]) > 0 ? true : false;
            string temp = System.Configuration.ConfigurationManager.AppSettings["UsasInformationPath"].ToString() + "Pic\\";

        
            FileInfo fn = new FileInfo(temp + dt.Rows[0]["ImgFile"].ToString());
            if (fn.Exists)
            {
                ccc.GetCacheView(CMS_Control_CacheView.ShowMode.Article, 20, dt.Rows[0]["BorderId"].ToString(), 
                    cinfo.GetEmpRole(), dt.Rows[0]["BorderName"].ToString(), num, RouterBar1.BarText, edit, true,
                    -1, "r," + System.Configuration.ConfigurationManager.AppSettings["UsasInformationIIS"].ToString() +
                    "Pic/" + fn.Name);
            }
            else
            {
                ccc.GetCacheView(CMS_Control_CacheView.ShowMode.Article, 20, dt.Rows[0]["BorderId"].ToString(), cinfo.GetEmpRole(), dt.Rows[0]["BorderName"].ToString(), num, RouterBar1.BarText, edit, true, -1, "");
            }
        }
        else
        {
            //内容页
            RouterBar1.IntiBar(CMS_Control_RouterBar.ShowMode.Article, Convert.ToInt32(Request["pid"]), new ArrayList());
            dt = ap.GetArticleTableBySetting(ro.GetSelfSettingRole(), "ArtId=" + Request["pid"], 1, -1, "ArtOrder");
            edit = Convert.ToInt32(dt.Rows[0]["edit"]) > 0 ? true : false;
            view = Convert.ToInt32(dt.Rows[0]["view"]) > 0 ? true : false;
         

            ccc.GetCacheView(CMS_Control_CacheView.ShowMode.ArticleSon, 20, dt.Rows[0]["ArtId"].ToString(), cinfo.GetEmpRole(), dt.Rows[0]["ArtTopic"].ToString(), num, RouterBar1.BarText, edit, true, -1, "");


        }

        ViewContent1.Controls.Add(ccc);

    }

    protected void agp_PageChanged(object sender, EventArgs e)
    {

    }
}
